package com.example.controller.other;

import com.example.common.Result;

import com.example.model.entity.other.ChatRole;
import com.example.service.other.ChatRoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 角色聊天表前端操作接口
 **/
@RestController
@RequestMapping("/chatRole")
public class ChatRoleController {

    @Resource
    private ChatRoleService chatRoleService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody ChatRole chatRole) {
        Map<String, Integer> integerMap = chatRoleService.add(chatRole);
        return Result.success(integerMap);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        chatRoleService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        chatRoleService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody ChatRole chatRole) {
        chatRoleService.updateById(chatRole);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ChatRole chatRole = chatRoleService.selectById(id);
        return Result.success(chatRole);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(ChatRole chatRole) {
        List<ChatRole> list = chatRoleService.selectAll(chatRole);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(ChatRole chatRole,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ChatRole> page = chatRoleService.selectPage(chatRole, pageNum, pageSize);
        return Result.success(page);
    }

}
